<div class="flex flex-wrap justify-between">
{{ if fileExists "ALLVERSIONS" }}
{{ $versions := os.ReadFile "ALLVERSIONS" }}
{{ $version := "nightly"}}
{{ if fileExists "VERSION" }}
{{ $version = os.ReadFile "VERSION" | strings.TrimLeft "\n" | strings.TrimRight "\n" }}
{{ end }}
{{ $splitted := split $versions "," }}
    <select name="version" id="version" onchange="javascript:handleVersion(this)">
        {{ range $splitted }}
            {{ $trimmed := strings.TrimLeft " " . | strings.TrimRight " " }}
            {{ if ne $trimmed $version }}
                <option value="{{ $trimmed }}">{{$trimmed}}</option>
            {{ else }}
                <option selected value="{{ $trimmed }}">{{$trimmed}}</option>
            {{ end }}
        {{ end }}
    </select>
    <script type="text/javascript">
      function handleVersion(elm)
      {
          current_page_path = window.location.pathname
          if (elm.value == "nightly")
          {
              window.location = "https://nightly.pipelines-as-code.pages.dev" + current_page_path
              return
          } else if (elm.value == "stable")
          {
              window.location = "https://pipelinesascode.com" + current_page_path
              return
          }
          var v = elm.value.replace(/\./g, "-");
          window.location = "https://release-" + v + ".pipelines-as-code.pages.dev" + current_page_path
      }
    </script>
{{ end }}

{{ if and .GitInfo .Site.Params.BookRepo }}
  <div>
    {{- $date := partial "docs/date" (dict "Date" .GitInfo.AuthorDate.Local "Format" .Site.Params.BookDateFormat) -}}
    {{- $commitPath := default "commit" .Site.Params.BookCommitPath -}}
    <a class="flex align-center" href="{{ .Site.Params.BookRepo }}/{{ $commitPath }}/{{ .GitInfo.Hash }}" title='{{ i18n "Last modified by" }} {{ .GitInfo.AuthorName }} | {{ $date }}' target="_blank" rel="noopener">
      <img src="{{ "svg/calendar.svg" | relURL }}" class="book-icon" alt="Calendar" />
      <span>{{ $date }}</span>
    </a>
  </div>
{{ end }}

{{ if and .File .Site.Params.BookRepo .Site.Params.BookEditPath }}
  <div>
    <a class="flex align-center" href="{{ .Site.Params.BookRepo }}/{{ .Site.Params.BookEditPath }}/{{ .Site.Params.contentDir | default "content" }}/{{ replace .File.Path "\\" "/" }}" target="_blank" rel="noopener">
      <img src="{{ "svg/edit.svg" | relURL }}" class="book-icon" alt="Edit" />
      <span>{{ i18n "Edit this page" }}</span>
    </a>
  </div>
{{ end }}

</div>

{{ $script := resources.Get "clipboard.js" | resources.Minify }}
{{ with $script.Content }}
  <script>{{ . | safeJS }}</script>
{{ end }}
